const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
  //入口文件
  entry: "./src/index.js",
  output: {
    //   输出文件名称
    filename: "bundle.js",
    //输出路径-绝对路径
    path: path.resolve(__dirname, "dist"),
  },
  // 模式
  mode: "development",

  // loader配置
  module: {
    // 对某个格式文件进行转换
    rules: [
      {
        test: /\.css$/,
        // use数组逆序执行
        use: [
          // 将js的样式插入到style标签里
          "style-loader",
          // 将css文件转换为js
          "css-loader",
        ],
      },
      {
        // 匹配图片
        test: /\.(jpg|png|gif)$/,
        loader: "url-loader",
        options: {
          limit: 8 * 1204,
          esModule: false,
          name: "[hash:10].[ext]",
        },
      },
      {
        test: /\.html$/,
        loader: "html-loader",
      },
    ],
  },

  // plugins插件配置
  plugins: [
    new HtmlWebpackPlugin({
      template: "src/index.html",
    }),
  ],
};
